/*
 * @Author: SimonCK666 SimonYang223@163.com
 * @Date: 2022-05-06 16:39:52
 * @LastEditors: SimonCK666 SimonYang223@163.com
 * @LastEditTime: 2022-05-06 16:58:37
 * @FilePath: \golang-concept\L2_goarray\mod.go
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package main

import "fmt"

func copy_slice() {
	var s1 = []int{1, 2, 3, 4}
	// 会同时修改
	var s2 = s1

	s2[0] = 100

	fmt.Println("s1 ", s1)
	fmt.Println("s2 ", s2)

	var s3 = []int{1, 2, 3, 4}
	var s4 = make([]int, 4)

	// 只会修改第二个，第一个不会修改
	copy(s4, s3)

	s4[0] = 100

	fmt.Println("s3 ", s3)
	fmt.Println("s4 ", s4)
}

func mod() {
	var s1 = []int{1, 2, 3, 4}

	// mod 1 --> 100
	s1[0] = 100

	fmt.Println(s1)
}

func del() {
	var s1 = []int{1, 2, 3, 4}
	// i 2 略过需要删除的索引值 append(s1[:index], s1[index + 1:]...)
	s2 := append(s1[:2], s1[3:]...)
	fmt.Println(s2)
}

func append_add() {
	var s1 = []int{}
	s1 = append(s1, 100)
	s1 = append(s1, 200)
	fmt.Println(s1)
}

func main() {
	append_add()
	del()
	mod()
	copy_slice()
}
